Skip to content

Conversation

@amsan
Copy link
Contributor

@amsan amsan commented Dec 4, 2018

This pull request fixes a bug that occurred under the following circumstances:

  • When calling manager.on_conflict(conflict_fields, ConflictAction.NOTHING).bulk_insert(...),
  • if conflict_fields includes the name of a ForeignKey field,
  • if the primary key of that field's related model is a UUIDField.

When attempting to do this, the following would happen:

  • bulk_insert would call _rewrite_insert_nothing(...)
  • where_clause would include something like foo_id = %s
  • _format_field_value("foo") would call prepare_value, passing it an instance of the Foo model
  • get_db_prep_save is called on the ForeignKey field
  • get_db_prep_save is called on Foo's primary key (a UUIDField)
  • UUIDField.to_python attempts to coerce the instance of the Foo model into a UUID, raising an error.

@Photonios
Copy link
Contributor

Thanks for your contribution 👍

Could you add a test to make sure this doesn't get broken again?

@Photonios Photonios force-pushed the master branch 5 times, most recently from c193e5d to 49d7a0b Compare January 11, 2019 11:40
@Photonios Photonios changed the base branch from master to fk-uuid-fix September 14, 2019 08:05
@Photonios Photonios merged commit 99fdef1 into SectorLabs:fk-uuid-fix Sep 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants